package com.wgchao.amc.autho;

import com.wgchao.amc.entity.base.SysBaseUser;
import com.wgchao.amc.repository.base.SysBaseUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @ClassName: DefaultUserInfoService
 * @author: wgchao
 * @createTime: 2019/11/1 1:36 PM
 * @Description: TODO
 */
@Component
public class DefaultUserInfoService implements UserInfoService {
    @Autowired
    private SysBaseUserRepository userRepository;

    @Override
    public UserInfo getUserInfo(Long userId) {
        Optional<SysBaseUser> userOptional = userRepository.findById(userId);
        if(userOptional.isPresent()){
            SysBaseUser user = userOptional.get();
            if(!user.isDel() && !user.isCancel()){
                UserInfo userInfo = new UserInfo();
                userInfo.setUserId(userId);
                userInfo.setAgencyCode(user.getAgencyCode());
                userInfo.setUname(user.getUname());
                userInfo.setUserType(user.getUtype());
                return userInfo;
            }
        }
        return null;
    }
}
